package com.yswy.theater.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yswy.theater.common.BasePojo;
import com.yswy.theater.entity.TheaterPlayType;
import com.yswy.theater.mapper.TheaterPlayTypeMapper;
import com.yswy.theater.service.TheaterPlayTypeService;
import com.yswy.theater.vo.res.TheaterPlayTypeResVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@Service
public class TheaterPlayTypeServiceImpl extends ServiceImpl<TheaterPlayTypeMapper, TheaterPlayType>
        implements TheaterPlayTypeService {


    @Override
    public List<TheaterPlayTypeResVo> listTheaterPlayType(Integer sex) {
        List<TheaterPlayType> listParent  = list(new LambdaQueryWrapper<TheaterPlayType>()
                .in(TheaterPlayType::getSex , 0,sex)
                .eq(TheaterPlayType::getHaveChildFlag , true)
                .eq(BasePojo::getIsDel , 0)
                .orderByDesc(TheaterPlayType::getSortId));
        List<TheaterPlayType> listSubset  = list(new LambdaQueryWrapper<TheaterPlayType>()
                .in(TheaterPlayType::getSex , 0,sex)
                .eq(TheaterPlayType::getHaveChildFlag , false)
                .eq(BasePojo::getIsDel , 0)
                .orderByDesc(TheaterPlayType::getSortId));
        List<TheaterPlayTypeResVo> typeParents = new ArrayList<>();
        for (TheaterPlayType t1:listParent ) {
            TheaterPlayTypeResVo typeParent = new TheaterPlayTypeResVo();
            typeParent.setTypeName(t1.getTypeName());
            typeParent.setId(t1.getId());
            List<TheaterPlayTypeResVo> typeSubsets = new ArrayList<>();
            for (TheaterPlayType t2:listSubset) {
//                System.out.println((t1.getId() == t2.getSkuLeveId() )+"  t1.getId() "+t1.getId()
//                        + "  t2.getSkuLeveId()"+t2.getSkuLeveId());
                if (t1.getId().equals(t2.getSkuLeveId())){
                    TheaterPlayTypeResVo typeSubset = new TheaterPlayTypeResVo();
                    typeSubset.setTypeName(t2.getTypeName());
                    typeSubset.setId(t2.getId());
                    typeSubsets.add(typeSubset);
                }
            }
            typeParent.setTheaterPlayResVos(typeSubsets);
            typeParents.add(typeParent);

        }
        return typeParents;
    }
}
